﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TCG.Engine.Effects;

namespace TCG.Engine.Core
{
    public class Player
    {
        public Player()
        {
            Hand = new List<Card>();
            Effects = new List<IEffect>();
        }

        public Player(PlayerOptions options): this()
        {
            //this.Deck = deck;
            this.Name = options.Name;

            this.Gold = options.StartGold;
            this.Mana = options.StartMana;

            this.GoldIncome = options.StartGoldIncome;
            this.ManaIncome = options.StartManaIncome;

            this.Life = options.StartLife;
        }

        public string Name { get; set; }

        public int GoldIncome { get; set; }
        public int ManaIncome { get; set; }

        public int Gold { get; set; }
        public int Mana { get; set; }

        public int Life { get; set; }

        public Deck Deck { get; set; }

        public List<Card> Hand { get; private set; }

        public IPlayerInteraction Interaction { get; set; }

        public Card Move(string cardId)
        {
            return Interaction.Move(cardId);
        }

        public void Draw()
        {
            Hand.Add(Deck.Draw());
        }

        public List<IEffect> Effects { get; private set; }

        public Player Clone()
        {
            var result = new Player();

            Copy(result, this);

            return result;
        }

        public Card HaveCard(string cardId)
        {
            var card = Deck.Contains(cardId);
            return card != null ? card : Hand.FirstOrDefault(c => c.Info.Id == cardId);
        }

        public static void Copy(Player to, Player from)
        {
            to.Name = from.Name;

            to.Deck = from.Deck;
            to.Effects = new List<IEffect>(from.Effects);

            to.Gold = from.Gold;
            to.GoldIncome = from.GoldIncome;
            
            to.Hand = new List<Card>(from.Hand);

            to.Interaction = from.Interaction;

            to.Life = from.Life;
            
            to.Mana = from.Mana;
            to.ManaIncome = from.ManaIncome;
        }
    }
}
